{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python Algorithmic Trading Cookbook"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Chapter 1: Handling and Manipulating Date, Time and Time Series Data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This Jupyter Notebook is created using Python version 3.8.2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Requirements"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can install the requirements for this Jupyter Notebook by executing the below cell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 1:  Creating datetime objects "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Approach #1: 2020-08-12 20:55:39.680195\n"
     ]
    }
   ],
   "source": [
    "dt1 = datetime.now()\n",
    "print(f'Approach #1: {dt1}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Year: 2020\n",
      "Month: 8\n",
      "Day: 12\n",
      "Hours: 20\n",
      "Minutes: 55\n",
      "Seconds: 39\n",
      "Microseconds: 680195\n",
      "Timezone: None\n"
     ]
    }
   ],
   "source": [
    "print(f'Year: {dt1.year}')\n",
    "print(f'Month: {dt1.month}')\n",
    "print(f'Day: {dt1.day}')\n",
    "print(f'Hours: {dt1.hour}')\n",
    "print(f'Minutes: {dt1.minute}')\n",
    "print(f'Seconds: {dt1.second}')\n",
    "print(f'Microseconds: {dt1.microsecond}')\n",
    "print(f'Timezone: {dt1.tzinfo}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Approach #2: 2021-01-01 00:00:00\n"
     ]
    }
   ],
   "source": [
    "dt2 = datetime(year=2021, month=1, day=1)\n",
    "print(f'Approach #2: {dt2}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Year: 2021\n",
      "Month: 1\n",
      "Day: 1\n",
      "Hours: 0\n",
      "Minutes: 0\n",
      "Seconds: 0\n",
      "Microseconds: 0\n",
      "Timezone: None\n"
     ]
    }
   ],
   "source": [
    "print(f'Year: {dt2.year}')\n",
    "print(f'Month: {dt2.month}')\n",
    "print(f'Day: {dt2.day}')\n",
    "print(f'Hours: {dt2.hour}')\n",
    "print(f'Minutes: {dt2.minute}')\n",
    "print(f'Seconds: {dt2.second}')\n",
    "print(f'Microseconds: {dt2.microsecond}')\n",
    "print(f'Timezone: {dt2.tzinfo}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Date: 2020-08-12\n",
      "Type: <class 'datetime.date'>\n"
     ]
    }
   ],
   "source": [
    "print(f\"Date: {dt1.date()}\")\n",
    "print(f\"Type: {type(dt1.date())}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time: 20:55:39.680195\n",
      "Type: <class 'datetime.time'>\n"
     ]
    }
   ],
   "source": [
    "print(f\"Time: {dt1.time()}\")\n",
    "print(f\"Type: {type(dt1.time())}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Date: 2021-01-01\n",
      "Type: <class 'datetime.date'>\n"
     ]
    }
   ],
   "source": [
    "print(f\"Date: {dt2.date()}\")\n",
    "print(f\"Type: {type(dt2.date())}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time: 00:00:00\n",
      "Type: <class 'datetime.time'>\n"
     ]
    }
   ],
   "source": [
    "print(f\"Time: {dt2.time()}\")\n",
    "print(f\"Type: {type(dt2.time())}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 2: Creating timedetla objects"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import timedelta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time difference: 5 days, 0:00:00\n"
     ]
    }
   ],
   "source": [
    "td1 = timedelta(days=5)\n",
    "print(f'Time difference: {td1}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time difference: 4 days, 0:00:00\n"
     ]
    }
   ],
   "source": [
    "td2 = timedelta(days=4)\n",
    "print(f'Time difference: {td2}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Addition: 5 days, 0:00:00 + 4 days, 0:00:00 = 9 days, 0:00:00\n"
     ]
    }
   ],
   "source": [
    "print(f'Addition: {td1} + {td2} = {td1 + td2}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Subtraction: 5 days, 0:00:00 - 4 days, 0:00:00 = 1 day, 0:00:00\n"
     ]
    }
   ],
   "source": [
    "print(f'Subtraction: {td1} - {td2} = {td1 - td2}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Multiplication: 5 days, 0:00:00 * 2.5 = 12 days, 12:00:00\n"
     ]
    }
   ],
   "source": [
    "print(f'Multiplication: {td1} * 2.5 = {td1 * 2.5}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time difference: 1 day, 0:00:00\n"
     ]
    }
   ],
   "source": [
    "td3 = timedelta(hours=23, minutes=59, seconds=60)\n",
    "print(f'Time difference: {td3}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total seconds in 1 day: 86400.0\n"
     ]
    }
   ],
   "source": [
    "print(f'Total seconds in 1 day: {td3.total_seconds()}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 3: Operations on datetime objects"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import date, datetime, timedelta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Today's Date: 2020-08-12\n"
     ]
    }
   ],
   "source": [
    "date_today = date.today()\n",
    "print(f\"Today's Date: {date_today}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Date 5 days later: 2020-08-17\n"
     ]
    }
   ],
   "source": [
    "date_5days_later = date_today + timedelta(days=5)\n",
    "print(f\"Date 5 days later: {date_5days_later}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Date 5 days ago: 2020-08-07\n"
     ]
    }
   ],
   "source": [
    "date_5days_ago = date_today - timedelta(days=5)\n",
    "print(f\"Date 5 days ago: {date_5days_ago}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_5days_later > date_5days_ago"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_5days_later < date_5days_ago"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_5days_later > date_today > date_5days_ago"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "current_timestamp = datetime.now()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time now: 20:55:45.239177\n"
     ]
    }
   ],
   "source": [
    "time_now = current_timestamp.time()\n",
    "print(f\"Time now: {time_now}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time 5 minutes later: 21:00:45.239177\n"
     ]
    }
   ],
   "source": [
    "time_5minutes_later = (current_timestamp + timedelta(minutes=5)).time()              # Note: operations are not allowed on time objects, so have to perform on datetime objects and then extract the time\n",
    "print(f\"Time 5 minutes later: {time_5minutes_later}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time 5 minutes ago: 20:50:45.239177\n"
     ]
    }
   ],
   "source": [
    "time_5minutes_ago = (current_timestamp - timedelta(minutes=5)).time()              # Note: operations are not allowed on time objects, so have to perform on datetime objects and then extract the time\n",
    "print(f\"Time 5 minutes ago: {time_5minutes_ago}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time_5minutes_later < time_5minutes_ago"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time_5minutes_later > time_5minutes_ago"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time_5minutes_later > time_now > time_5minutes_ago"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 4: Modifying datetime objects"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020-08-12 20:55:46.753899\n"
     ]
    }
   ],
   "source": [
    "dt1 = datetime.now()\n",
    "print(dt1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A timestamp from 1st January 2021: 2021-01-01 20:55:46.753899\n"
     ]
    }
   ],
   "source": [
    "dt2 = dt1.replace(year=2021, month=1, day=1)\n",
    "print(f'A timestamp from 1st January 2021: {dt2}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A timestamp from 1st January 2021: 2021-01-01 20:55:46.753899\n"
     ]
    }
   ],
   "source": [
    "dt3 = datetime(year=2021, \n",
    "               month=1, \n",
    "               day=1, \n",
    "               hour=dt1.hour, \n",
    "               minute=dt1.minute, \n",
    "               second=dt1.second, \n",
    "               microsecond=dt1.microsecond, \n",
    "               tzinfo=dt1.tzinfo)\n",
    "print(f'A timestamp from 1st January 2021: {dt3}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt2 == dt3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 5: Converting a datetime object to a string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "now = datetime.now().astimezone()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020-08-12 20:55:48.366130+05:30\n"
     ]
    }
   ],
   "source": [
    "print(str(now))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12-08-2020 20:55:48 +0530\n"
     ]
    }
   ],
   "source": [
    "print(now.strftime(\"%d-%m-%Y %H:%M:%S %z\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 6: Creating a datetime object from a string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "now_str = '13-1-2021 15:53:39 +05:30'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-01-13 15:53:39+05:30\n"
     ]
    }
   ],
   "source": [
    "now = datetime.strptime(now_str, \"%d-%m-%Y %H:%M:%S %z\")\n",
    "print(now)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'datetime.datetime'>\n"
     ]
    }
   ],
   "source": [
    "print(type(now))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "unconverted data remains:  15:53:39 +05:30",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-45-dc92a0358ed8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnow\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstrptime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnow_str\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"%d-%m-%Y\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;31m# Note: It's expected to get an error below\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/lib/python3.8/_strptime.py\u001b[0m in \u001b[0;36m_strptime_datetime\u001b[0;34m(cls, data_string, format)\u001b[0m\n\u001b[1;32m    566\u001b[0m     \"\"\"Return a class cls instance based on the input string and the\n\u001b[1;32m    567\u001b[0m     format string.\"\"\"\n\u001b[0;32m--> 568\u001b[0;31m     \u001b[0mtt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfraction\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgmtoff_fraction\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_strptime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata_string\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mformat\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    569\u001b[0m     \u001b[0mtzname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgmtoff\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    570\u001b[0m     \u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;36m6\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mfraction\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/lib/python3.8/_strptime.py\u001b[0m in \u001b[0;36m_strptime\u001b[0;34m(data_string, format)\u001b[0m\n\u001b[1;32m    350\u001b[0m                          (data_string, format))\n\u001b[1;32m    351\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata_string\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mfound\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 352\u001b[0;31m         raise ValueError(\"unconverted data remains: %s\" %\n\u001b[0m\u001b[1;32m    353\u001b[0m                           data_string[found.end():])\n\u001b[1;32m    354\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: unconverted data remains:  15:53:39 +05:30"
     ]
    }
   ],
   "source": [
    "now = datetime.strptime(now_str, \"%d-%m-%Y\")\n",
    "# Note: It's expected to get an error below"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 7: The datetime object and time zones"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020-08-12 20:55:50.598800\n"
     ]
    }
   ],
   "source": [
    "now_tz_naive = datetime.now()                   # Timezone naive datetime object\n",
    "print(now_tz_naive)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(now_tz_naive.tzinfo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020-08-12 20:55:51.004671+05:30\n"
     ]
    }
   ],
   "source": [
    "now_tz_aware = datetime.now().astimezone()      # Timezone aware datetime object\n",
    "print(now_tz_aware)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IST\n"
     ]
    }
   ],
   "source": [
    "print(now_tz_aware.tzinfo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020-08-12 20:55:50.598800+05:30\n"
     ]
    }
   ],
   "source": [
    "new_tz_aware = now_tz_naive.replace(tzinfo=now_tz_aware.tzinfo)\n",
    "print(new_tz_aware)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IST\n"
     ]
    }
   ],
   "source": [
    "print(new_tz_aware.tzinfo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020-08-12 20:55:50.598800\n"
     ]
    }
   ],
   "source": [
    "new_tz_naive = new_tz_aware.replace(tzinfo=None)\n",
    "print(new_tz_naive)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(new_tz_naive.tzinfo)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_tz_naive <= now_tz_naive"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_tz_aware <= now_tz_aware"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can't compare offset-naive and offset-aware datetimes",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-57-a9433bb51293>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnew_tz_aware\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0mnow_tz_naive\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;31m# Note: It's expected to get an error below\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: can't compare offset-naive and offset-aware datetimes"
     ]
    }
   ],
   "source": [
    "new_tz_aware <= now_tz_naive\n",
    "# Note: It's expected to get an error below"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 8: Creating a Pandas.Dataframe object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "import pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "time_series_data = [\n",
    "    {'date': datetime(2019, 11, 13, 9, 0),\n",
    "     'open': 71.8075,\n",
    "     'high': 71.845,\n",
    "     'low': 71.7775,\n",
    "     'close': 71.7925,\n",
    "     'volume': 219512},\n",
    "    {'date': datetime(2019, 11, 13, 9, 15),\n",
    "     'open': 71.7925,\n",
    "     'high': 71.8,\n",
    "     'low': 71.78,\n",
    "     'close': 71.7925,\n",
    "     'volume': 59252},\n",
    "    {'date': datetime(2019, 11, 13, 9, 30),\n",
    "     'open': 71.7925,\n",
    "     'high': 71.8125,\n",
    "     'low': 71.76,\n",
    "     'close': 71.7625,\n",
    "     'volume': 57187},\n",
    "    {'date': datetime(2019, 11, 13, 9, 45),\n",
    "     'open': 71.76,\n",
    "     'high': 71.765,\n",
    "     'low': 71.735,\n",
    "     'close': 71.7425,\n",
    "     'volume': 43048},\n",
    "    {'date': datetime(2019, 11, 13, 10, 0),\n",
    "     'open': 71.7425,\n",
    "     'high': 71.78,\n",
    "     'low': 71.7425,\n",
    "     'close': 71.7775,\n",
    "     'volume': 45863},\n",
    "    {'date': datetime(2019, 11, 13, 10, 15),\n",
    "     'open': 71.775,\n",
    "     'high': 71.8225,\n",
    "     'low': 71.77,\n",
    "     'close': 71.815,\n",
    "     'volume': 42460},\n",
    "    {'date': datetime(2019, 11, 13, 10, 30),\n",
    "     'open': 71.815,\n",
    "     'high': 71.83,\n",
    "     'low': 71.7775,\n",
    "     'close': 71.78,\n",
    "     'volume': 62403},\n",
    "    {'date': datetime(2019, 11, 13, 10, 45),\n",
    "     'open': 71.775,\n",
    "     'high': 71.7875,\n",
    "     'low': 71.7475,\n",
    "     'close': 71.7525,\n",
    "     'volume': 34090},\n",
    "    {'date': datetime(2019, 11, 13, 11, 0),\n",
    "     'open': 71.7525,\n",
    "     'high': 71.7825,\n",
    "     'low': 71.7475,\n",
    "     'close': 71.7625,\n",
    "     'volume': 39320},\n",
    "    {'date': datetime(2019, 11, 13, 11, 15),\n",
    "     'open': 71.7625,\n",
    "     'high': 71.7925,\n",
    "     'low': 71.76,\n",
    "     'close': 71.7875,\n",
    "     'volume': 20190}\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-11-13 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-11-13 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-11-13 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-11-13 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-11-13 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2019-11-13 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2019-11-13 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2019-11-13 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2019-11-13 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2019-11-13 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 date     open     high      low    close  volume\n",
       "0 2019-11-13 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "1 2019-11-13 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "2 2019-11-13 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "3 2019-11-13 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "4 2019-11-13 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "5 2019-11-13 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "6 2019-11-13 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "7 2019-11-13 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "8 2019-11-13 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "9 2019-11-13 11:15:00  71.7625  71.7925  71.7600  71.7875   20190"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pandas.DataFrame(time_series_data)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['date', 'open', 'high', 'low', 'close', 'volume']"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>close</th>\n",
       "      <th>date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>71.7925</td>\n",
       "      <td>2019-11-13 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>71.7925</td>\n",
       "      <td>2019-11-13 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>71.7625</td>\n",
       "      <td>2019-11-13 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>71.7425</td>\n",
       "      <td>2019-11-13 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>71.7775</td>\n",
       "      <td>2019-11-13 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>71.8150</td>\n",
       "      <td>2019-11-13 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>71.7800</td>\n",
       "      <td>2019-11-13 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>71.7525</td>\n",
       "      <td>2019-11-13 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>71.7625</td>\n",
       "      <td>2019-11-13 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>71.7875</td>\n",
       "      <td>2019-11-13 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     close                date     open     high      low  volume\n",
       "0  71.7925 2019-11-13 09:00:00  71.8075  71.8450  71.7775  219512\n",
       "1  71.7925 2019-11-13 09:15:00  71.7925  71.8000  71.7800   59252\n",
       "2  71.7625 2019-11-13 09:30:00  71.7925  71.8125  71.7600   57187\n",
       "3  71.7425 2019-11-13 09:45:00  71.7600  71.7650  71.7350   43048\n",
       "4  71.7775 2019-11-13 10:00:00  71.7425  71.7800  71.7425   45863\n",
       "5  71.8150 2019-11-13 10:15:00  71.7750  71.8225  71.7700   42460\n",
       "6  71.7800 2019-11-13 10:30:00  71.8150  71.8300  71.7775   62403\n",
       "7  71.7525 2019-11-13 10:45:00  71.7750  71.7875  71.7475   34090\n",
       "8  71.7625 2019-11-13 11:00:00  71.7525  71.7825  71.7475   39320\n",
       "9  71.7875 2019-11-13 11:15:00  71.7625  71.7925  71.7600   20190"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas.DataFrame(time_series_data, \n",
    "    columns=['close', 'date', 'open', 'high', 'low', 'volume'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2019-11-13 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2019-11-13 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2019-11-13 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2019-11-13 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2019-11-13 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2019-11-13 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2019-11-13 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2019-11-13 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2019-11-13 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2019-11-13 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  date     open     high      low    close  volume\n",
       "10 2019-11-13 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "11 2019-11-13 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "12 2019-11-13 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "13 2019-11-13 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "14 2019-11-13 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "15 2019-11-13 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "16 2019-11-13 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "17 2019-11-13 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "18 2019-11-13 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "19 2019-11-13 11:15:00  71.7625  71.7925  71.7600  71.7875   20190"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas.DataFrame(time_series_data, index=range(10, 20))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipes 9: Dataframe manipulation: renaming, rearranging, reversing, and slicing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-11-13 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-11-13 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-11-13 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-11-13 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-11-13 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2019-11-13 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2019-11-13 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2019-11-13 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2019-11-13 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2019-11-13 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            timestamp     open     high      low    close  volume\n",
       "0 2019-11-13 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "1 2019-11-13 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "2 2019-11-13 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "3 2019-11-13 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "4 2019-11-13 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "5 2019-11-13 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "6 2019-11-13 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "7 2019-11-13 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "8 2019-11-13 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "9 2019-11-13 11:15:00  71.7625  71.7925  71.7600  71.7875   20190"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.rename(columns={'date':'timestamp'}, inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>volume</th>\n",
       "      <th>close</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>high</th>\n",
       "      <th>open</th>\n",
       "      <th>low</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>219512</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>2019-11-13 09:00:00</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.7775</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>59252</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>2019-11-13 09:15:00</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>57187</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>2019-11-13 09:30:00</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>43048</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>2019-11-13 09:45:00</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>45863</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>2019-11-13 10:00:00</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7425</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>42460</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>2019-11-13 10:15:00</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>62403</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>2019-11-13 10:30:00</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.7775</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>34090</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>2019-11-13 10:45:00</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>39320</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>2019-11-13 11:00:00</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>20190</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>2019-11-13 11:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   volume    close           timestamp     high     open      low\n",
       "0  219512  71.7925 2019-11-13 09:00:00  71.8450  71.8075  71.7775\n",
       "1   59252  71.7925 2019-11-13 09:15:00  71.8000  71.7925  71.7800\n",
       "2   57187  71.7625 2019-11-13 09:30:00  71.8125  71.7925  71.7600\n",
       "3   43048  71.7425 2019-11-13 09:45:00  71.7650  71.7600  71.7350\n",
       "4   45863  71.7775 2019-11-13 10:00:00  71.7800  71.7425  71.7425\n",
       "5   42460  71.8150 2019-11-13 10:15:00  71.8225  71.7750  71.7700\n",
       "6   62403  71.7800 2019-11-13 10:30:00  71.8300  71.8150  71.7775\n",
       "7   34090  71.7525 2019-11-13 10:45:00  71.7875  71.7750  71.7475\n",
       "8   39320  71.7625 2019-11-13 11:00:00  71.7825  71.7525  71.7475\n",
       "9   20190  71.7875 2019-11-13 11:15:00  71.7925  71.7625  71.7600"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.reindex(columns=[\n",
    "    'volume', \n",
    "    'close', \n",
    "    'timestamp', \n",
    "    'high', \n",
    "    'open', \n",
    "    'low'\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2019-11-13 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2019-11-13 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2019-11-13 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2019-11-13 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2019-11-13 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-11-13 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-11-13 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-11-13 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-11-13 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-11-13 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            timestamp     open     high      low    close  volume\n",
       "9 2019-11-13 11:15:00  71.7625  71.7925  71.7600  71.7875   20190\n",
       "8 2019-11-13 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "7 2019-11-13 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "6 2019-11-13 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "5 2019-11-13 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "4 2019-11-13 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "3 2019-11-13 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "2 2019-11-13 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "1 2019-11-13 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "0 2019-11-13 09:00:00  71.8075  71.8450  71.7775  71.7925  219512"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    71.7925\n",
       "1    71.7925\n",
       "2    71.7625\n",
       "3    71.7425\n",
       "4    71.7775\n",
       "5    71.8150\n",
       "6    71.7800\n",
       "7    71.7525\n",
       "8    71.7625\n",
       "9    71.7875\n",
       "Name: close, dtype: float64"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['close']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "timestamp    2019-11-13 09:00:00\n",
       "open                     71.8075\n",
       "high                      71.845\n",
       "low                      71.7775\n",
       "close                    71.7925\n",
       "volume                    219512\n",
       "Name: 0, dtype: object"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-11-13 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-11-13 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            timestamp     open\n",
       "0 2019-11-13 09:00:00  71.8075\n",
       "1 2019-11-13 09:15:00  71.7925"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:2, :2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    71.7925\n",
       "1    71.7925\n",
       "2    71.7625\n",
       "3    71.7425\n",
       "4    71.7775\n",
       "5    71.8150\n",
       "6    71.7800\n",
       "7    71.7525\n",
       "8    71.7625\n",
       "9    71.7875\n",
       "Name: close, dtype: float64"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:, 4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipes 10: Dataframe Manipulation: applying, sorting, iterating and concatenating"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>13-11-2019 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13-11-2019 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13-11-2019 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13-11-2019 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13-11-2019 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>13-11-2019 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>13-11-2019 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>13-11-2019 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>13-11-2019 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>13-11-2019 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             timestamp     open     high      low    close  volume\n",
       "0  13-11-2019 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "1  13-11-2019 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "2  13-11-2019 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "3  13-11-2019 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "4  13-11-2019 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "5  13-11-2019 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "6  13-11-2019 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "7  13-11-2019 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "8  13-11-2019 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "9  13-11-2019 11:15:00  71.7625  71.7925  71.7600  71.7875   20190"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['timestamp'] = df['timestamp'].apply(\n",
    "    lambda x: x.strftime(\"%d-%m-%Y %H:%M:%S\"))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13-11-2019 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>13-11-2019 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13-11-2019 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>13-11-2019 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13-11-2019 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>13-11-2019 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>13-11-2019 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>13-11-2019 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13-11-2019 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>13-11-2019 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             timestamp     open     high      low    close  volume\n",
       "3  13-11-2019 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "7  13-11-2019 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "2  13-11-2019 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "8  13-11-2019 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "4  13-11-2019 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "6  13-11-2019 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "9  13-11-2019 11:15:00  71.7625  71.7925  71.7600  71.7875   20190\n",
       "0  13-11-2019 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "1  13-11-2019 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "5  13-11-2019 10:15:00  71.7750  71.8225  71.7700  71.8150   42460"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values(by='close', ascending=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>13-11-2019 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>13-11-2019 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13-11-2019 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13-11-2019 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>13-11-2019 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>13-11-2019 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>13-11-2019 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13-11-2019 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>13-11-2019 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13-11-2019 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             timestamp     open     high      low    close  volume\n",
       "6  13-11-2019 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "0  13-11-2019 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "1  13-11-2019 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "2  13-11-2019 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "5  13-11-2019 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "7  13-11-2019 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "9  13-11-2019 11:15:00  71.7625  71.7925  71.7600  71.7875   20190\n",
       "3  13-11-2019 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "8  13-11-2019 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "4  13-11-2019 10:00:00  71.7425  71.7800  71.7425  71.7775   45863"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values(by='open', ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index: 0 | Average: 71.805625\n",
      "Index: 1 | Average: 71.79124999999999\n",
      "Index: 2 | Average: 71.781875\n",
      "Index: 3 | Average: 71.750625\n",
      "Index: 4 | Average: 71.760625\n",
      "Index: 5 | Average: 71.795625\n",
      "Index: 6 | Average: 71.800625\n",
      "Index: 7 | Average: 71.765625\n",
      "Index: 8 | Average: 71.76124999999999\n",
      "Index: 9 | Average: 71.775625\n"
     ]
    }
   ],
   "source": [
    "for _, row in df.iterrows():\n",
    "    avg = (row['open'] + row['close'] + row['high'] + row['low'])/4\n",
    "    print(f\"Index: {_} | Average: {avg}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13-11-2019 09:00:00\n",
      "71.8075\n",
      "71.845\n",
      "71.7775\n",
      "71.7925\n",
      "219512\n"
     ]
    }
   ],
   "source": [
    "for value in df.iloc[0]:\n",
    "    print(value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-11-13 11:30:00</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>18655</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-11-13 11:45:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8050</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>25648</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-11-13 12:00:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.8050</td>\n",
       "      <td>71.7500</td>\n",
       "      <td>71.7850</td>\n",
       "      <td>37300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-11-13 12:15:00</td>\n",
       "      <td>71.7850</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7575</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>15431</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-11-13 12:30:00</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7950</td>\n",
       "      <td>71.7725</td>\n",
       "      <td>71.7900</td>\n",
       "      <td>5178</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            timestamp     open     high      low    close  volume\n",
       "0 2019-11-13 11:30:00  71.7875  71.8075  71.7700  71.7925   18655\n",
       "1 2019-11-13 11:45:00  71.7925  71.8050  71.7625  71.7625   25648\n",
       "2 2019-11-13 12:00:00  71.7625  71.8050  71.7500  71.7850   37300\n",
       "3 2019-11-13 12:15:00  71.7850  71.7925  71.7575  71.7775   15431\n",
       "4 2019-11-13 12:30:00  71.7775  71.7950  71.7725  71.7900    5178"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_new = pandas.DataFrame([\n",
    "    {'timestamp': datetime(2019, 11, 13, 11, 30),\n",
    "     'open': 71.7875,\n",
    "     'high': 71.8075,\n",
    "     'low': 71.77,\n",
    "     'close': 71.7925,\n",
    "     'volume': 18655},\n",
    "    {'timestamp': datetime(2019, 11, 13, 11, 45),\n",
    "     'open': 71.7925,\n",
    "     'high': 71.805,\n",
    "     'low': 71.7625,\n",
    "     'close': 71.7625,\n",
    "     'volume': 25648},\n",
    "    {'timestamp': datetime(2019, 11, 13, 12, 0),\n",
    "     'open': 71.7625,\n",
    "     'high': 71.805,\n",
    "     'low': 71.75,\n",
    "     'close': 71.785,\n",
    "     'volume': 37300},\n",
    "    {'timestamp': datetime(2019, 11, 13, 12, 15),\n",
    "     'open': 71.785,\n",
    "     'high': 71.7925,\n",
    "     'low': 71.7575,\n",
    "     'close': 71.7775,\n",
    "     'volume': 15431},\n",
    "    {'timestamp': datetime(2019, 11, 13, 12, 30),\n",
    "     'open': 71.7775,\n",
    "     'high': 71.795,\n",
    "     'low': 71.7725,\n",
    "     'close': 71.79,\n",
    "     'volume': 5178}\n",
    "])\n",
    "df_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>13-11-2019 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13-11-2019 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13-11-2019 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13-11-2019 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13-11-2019 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>13-11-2019 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>13-11-2019 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>13-11-2019 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>13-11-2019 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>13-11-2019 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2019-11-13 11:30:00</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>18655</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2019-11-13 11:45:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8050</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>25648</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2019-11-13 12:00:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.8050</td>\n",
       "      <td>71.7500</td>\n",
       "      <td>71.7850</td>\n",
       "      <td>37300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2019-11-13 12:15:00</td>\n",
       "      <td>71.7850</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7575</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>15431</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2019-11-13 12:30:00</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7950</td>\n",
       "      <td>71.7725</td>\n",
       "      <td>71.7900</td>\n",
       "      <td>5178</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              timestamp     open     high      low    close  volume\n",
       "0   13-11-2019 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "1   13-11-2019 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "2   13-11-2019 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "3   13-11-2019 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "4   13-11-2019 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "5   13-11-2019 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "6   13-11-2019 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "7   13-11-2019 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "8   13-11-2019 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "9   13-11-2019 11:15:00  71.7625  71.7925  71.7600  71.7875   20190\n",
       "10  2019-11-13 11:30:00  71.7875  71.8075  71.7700  71.7925   18655\n",
       "11  2019-11-13 11:45:00  71.7925  71.8050  71.7625  71.7625   25648\n",
       "12  2019-11-13 12:00:00  71.7625  71.8050  71.7500  71.7850   37300\n",
       "13  2019-11-13 12:15:00  71.7850  71.7925  71.7575  71.7775   15431\n",
       "14  2019-11-13 12:30:00  71.7775  71.7950  71.7725  71.7900    5178"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas.concat([df, df_new]).reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   open\n",
       "0    99\n",
       "1    73\n",
       "2    16\n",
       "3    53\n",
       "4    47\n",
       "5    74\n",
       "6    21\n",
       "7    22\n",
       "8     2\n",
       "9    30"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = pandas.DataFrame([random.randint(1,100) for i in range(10)], \n",
    "                       columns=['open'])\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   close\n",
       "0     63\n",
       "1     84\n",
       "2     44\n",
       "3     56\n",
       "4     25\n",
       "5      1\n",
       "6     41\n",
       "7     55\n",
       "8     93\n",
       "9     82"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = pandas.DataFrame([random.randint(1,100) for i in range(10)], \n",
    "                       columns=['close'])\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>99</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>73</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>16</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>53</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>47</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>74</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>21</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>22</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>30</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   open  close\n",
       "0    99     63\n",
       "1    73     84\n",
       "2    16     44\n",
       "3    53     56\n",
       "4    47     25\n",
       "5    74      1\n",
       "6    21     41\n",
       "7    22     55\n",
       "8     2     93\n",
       "9    30     82"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas.concat([df1, df2], axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 11: Converting a DataFrame into other formats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('dataframe.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"timestamp\":{\"0\":\"13-11-2019 09:00:00\",\"1\":\"13-11-2019 09:15:00\",\"2\":\"13-11-2019 09:30:00\",\"3\":\"13-11-2019 09:45:00\",\"4\":\"13-11-2019 10:00:00\",\"5\":\"13-11-2019 10:15:00\",\"6\":\"13-11-2019 10:30:00\",\"7\":\"13-11-2019 10:45:00\",\"8\":\"13-11-2019 11:00:00\",\"9\":\"13-11-2019 11:15:00\"},\"open\":{\"0\":71.8075,\"1\":71.7925,\"2\":71.7925,\"3\":71.76,\"4\":71.7425,\"5\":71.775,\"6\":71.815,\"7\":71.775,\"8\":71.7525,\"9\":71.7625},\"high\":{\"0\":71.845,\"1\":71.8,\"2\":71.8125,\"3\":71.765,\"4\":71.78,\"5\":71.8225,\"6\":71.83,\"7\":71.7875,\"8\":71.7825,\"9\":71.7925},\"low\":{\"0\":71.7775,\"1\":71.78,\"2\":71.76,\"3\":71.735,\"4\":71.7425,\"5\":71.77,\"6\":71.7775,\"7\":71.7475,\"8\":71.7475,\"9\":71.76},\"close\":{\"0\":71.7925,\"1\":71.7925,\"2\":71.7625,\"3\":71.7425,\"4\":71.7775,\"5\":71.815,\"6\":71.78,\"7\":71.7525,\"8\":71.7625,\"9\":71.7875},\"volume\":{\"0\":219512,\"1\":59252,\"2\":57187,\"3\":43048,\"4\":45863,\"5\":42460,\"6\":62403,\"7\":34090,\"8\":39320,\"9\":20190}}'"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.to_json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_pickle('df.pickle')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 12: Creating a DataFrame from other formats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>13-11-2019 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13-11-2019 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13-11-2019 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13-11-2019 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13-11-2019 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>13-11-2019 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>13-11-2019 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>13-11-2019 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>13-11-2019 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>13-11-2019 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             timestamp     open     high      low    close  volume\n",
       "0  13-11-2019 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "1  13-11-2019 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "2  13-11-2019 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "3  13-11-2019 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "4  13-11-2019 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "5  13-11-2019 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "6  13-11-2019 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "7  13-11-2019 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "8  13-11-2019 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "9  13-11-2019 11:15:00  71.7625  71.7925  71.7600  71.7875   20190"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas.read_csv('dataframe.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-11-13 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-11-13 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-11-13 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-11-13 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-11-13 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2019-11-13 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2019-11-13 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2019-11-13 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2019-11-13 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2019-11-13 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            timestamp     open     high      low    close  volume\n",
       "0 2019-11-13 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "1 2019-11-13 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "2 2019-11-13 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "3 2019-11-13 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "4 2019-11-13 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "5 2019-11-13 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "6 2019-11-13 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "7 2019-11-13 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "8 2019-11-13 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "9 2019-11-13 11:15:00  71.7625  71.7925  71.7600  71.7875   20190"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas.read_json('{\"timestamp\":{\"0\":\"13-11-2019 09:00:00\",\"1\":\"13-11-2019 09:15:00\",\"2\":\"13-11-2019 09:30:00\",\"3\":\"13-11-2019 09:45:00\",\"4\":\"13-11-2019 10:00:00\",\"5\":\"13-11-2019 10:15:00\",\"6\":\"13-11-2019 10:30:00\",\"7\":\"13-11-2019 10:45:00\",\"8\":\"13-11-2019 11:00:00\",\"9\":\"13-11-2019 11:15:00\"},\"open\":{\"0\":71.8075,\"1\":71.7925,\"2\":71.7925,\"3\":71.76,\"4\":71.7425,\"5\":71.775,\"6\":71.815,\"7\":71.775,\"8\":71.7525,\"9\":71.7625},\"high\":{\"0\":71.845,\"1\":71.8,\"2\":71.8125,\"3\":71.765,\"4\":71.78,\"5\":71.8225,\"6\":71.83,\"7\":71.7875,\"8\":71.7825,\"9\":71.7925},\"low\":{\"0\":71.7775,\"1\":71.78,\"2\":71.76,\"3\":71.735,\"4\":71.7425,\"5\":71.77,\"6\":71.7775,\"7\":71.7475,\"8\":71.7475,\"9\":71.76},\"close\":{\"0\":71.7925,\"1\":71.7925,\"2\":71.7625,\"3\":71.7425,\"4\":71.7775,\"5\":71.815,\"6\":71.78,\"7\":71.7525,\"8\":71.7625,\"9\":71.7875},\"volume\":{\"0\":219512,\"1\":59252,\"2\":57187,\"3\":43048,\"4\":45863,\"5\":42460,\"6\":62403,\"7\":34090,\"8\":39320,\"9\":20190}}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>13-11-2019 09:00:00</td>\n",
       "      <td>71.8075</td>\n",
       "      <td>71.8450</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>219512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13-11-2019 09:15:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8000</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>59252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13-11-2019 09:30:00</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.8125</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>57187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13-11-2019 09:45:00</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7650</td>\n",
       "      <td>71.7350</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>43048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13-11-2019 10:00:00</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>71.7425</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>45863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>13-11-2019 10:15:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.8225</td>\n",
       "      <td>71.7700</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>42460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>13-11-2019 10:30:00</td>\n",
       "      <td>71.8150</td>\n",
       "      <td>71.8300</td>\n",
       "      <td>71.7775</td>\n",
       "      <td>71.7800</td>\n",
       "      <td>62403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>13-11-2019 10:45:00</td>\n",
       "      <td>71.7750</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>34090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>13-11-2019 11:00:00</td>\n",
       "      <td>71.7525</td>\n",
       "      <td>71.7825</td>\n",
       "      <td>71.7475</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>39320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>13-11-2019 11:15:00</td>\n",
       "      <td>71.7625</td>\n",
       "      <td>71.7925</td>\n",
       "      <td>71.7600</td>\n",
       "      <td>71.7875</td>\n",
       "      <td>20190</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             timestamp     open     high      low    close  volume\n",
       "0  13-11-2019 09:00:00  71.8075  71.8450  71.7775  71.7925  219512\n",
       "1  13-11-2019 09:15:00  71.7925  71.8000  71.7800  71.7925   59252\n",
       "2  13-11-2019 09:30:00  71.7925  71.8125  71.7600  71.7625   57187\n",
       "3  13-11-2019 09:45:00  71.7600  71.7650  71.7350  71.7425   43048\n",
       "4  13-11-2019 10:00:00  71.7425  71.7800  71.7425  71.7775   45863\n",
       "5  13-11-2019 10:15:00  71.7750  71.8225  71.7700  71.8150   42460\n",
       "6  13-11-2019 10:30:00  71.8150  71.8300  71.7775  71.7800   62403\n",
       "7  13-11-2019 10:45:00  71.7750  71.7875  71.7475  71.7525   34090\n",
       "8  13-11-2019 11:00:00  71.7525  71.7825  71.7475  71.7625   39320\n",
       "9  13-11-2019 11:15:00  71.7625  71.7925  71.7600  71.7875   20190"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pandas.read_pickle('df.pickle')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
